//-----------------------------------------------------------------------------
/// STATE_IGM (Implementation)
//-----------------------------------------------------------------------------
START_STATE_CODE( STATE_IGM )
{
    START_MESSAGE_HANDLER( MESSAGE_ENTER )
    {
		InitIGM();
    }

    START_MESSAGE_HANDLER( MESSAGE_UPDATE )
    {		
		UpdateIGM();
    }

    START_MESSAGE_HANDLER( MESSAGE_PAINT )
    {
		// StateMainMenuPaint(s_gBackBuffer);
		PaintIGM(s_gBackBuffer);
    }

    START_MESSAGE_HANDLER( MESSAGE_EXIT )
    {
		// GameDestroy();
		// StateLogoExit();
		ExitIGM();
    }

	START_MESSAGE_HANDLER( MESSAGE_HIDENOTIFY )
	{
		// GameHideNotify();
	}
}

static int[] _menu_IGM =
{
	TEXT.MENU_IGM,
	TEXT.MENU_RESUME,
	TEXT.MENU_RESTART,
	TEXT.MENU_MAIN_MENU,
	TEXT.MENU_HELP,
	TEXT.MENU_EXIT,
};

static void InitIGM()
{
	try
	{
		s_imgBackground = Image.createImage("/bg_IGM.png");
	}
	catch(Exception ex)
	{
		s_imgBackground = Image.createImage(s_iWidth, s_iHeight);
		Graphics g = s_imgBackground.getGraphics();
		g.setColor(255, 0, 0);
		g.drawString("InitIGM() error!",10,20,0);
		g.drawString(ex.toString(),10,50,0);
	}
	_menu_item_focused = _menu_last_item_selected;
	// _menu_item_focused = 0;
	_menu_item_selected = -1;
	_menu_y = 320 - _menu_IGM.length * (MENU_HEIGHT+_menu_spacing) - 20;
	SetSoftkey(false, false);
}
static void Update_IGM_Selected()
{
	switch(_menu_item_selected)
	{
		case TEXT.MENU_RESUME:
			System.out.println(">>>>>>>>>>>> Selecet Button "+GetString(TEXT.MENU_RESUME));
			SwitchState(STATE_GAMEPLAY);
			break;
		case TEXT.MENU_MAIN_MENU:
			SwitchState(STATE_MM_CONFIRM);
		case TEXT.MENU_RESTART:
			break;
		case TEXT.MENU_HELP:
			break;
		case TEXT.MENU_EXIT:
			SwitchState(STATE_EXIT_CONFIRM);
			break;
		default:
			break;
	}
}
static void UpdateIGM()
{
	switch(s_iPressedKey)
	{
		case CanvasKeys.NUM2:
		case CanvasKeys.UP:
			if(_menu_item_focused == 0)
				_menu_item_focused = _menu_IGM.length-2;
			else
				_menu_item_focused --;
			break;
		case CanvasKeys.NUM8:
		case CanvasKeys.DOWN:
			if(_menu_item_focused == _menu_IGM.length-2)
				_menu_item_focused = 0;
			else
				_menu_item_focused ++;
			break;
		case CanvasKeys.NUM5:
		case CanvasKeys.SELECT:
			break;
		default:
			break;
	}
	switch(s_iReleasedKey)
	{
		case CanvasKeys.NUM5:
		case CanvasKeys.SELECT:
			_menu_item_selected = _menu_IGM[_menu_item_focused+1];
			Update_IGM_Selected();
			break;		
		default:
			break;
	}
}

static void PaintIGM(Graphics g)
{
	g.drawImage(s_imgBackground, 0, 0, 0);
	DrawMenu(g, _menu_IGM, true);
}

static void ExitIGM()
{
	s_imgBackground = null;
	_menu_last_item_selected = _menu_item_selected;
}
